<?php

/**
 * This is the model class for table "statusacuerdoparticipante".
 *
 * The followings are the available columns in table 'statusacuerdoparticipante':
 * @property integer $id
 * @property integer $id_acuerdo
 * @property integer $id_usuario
 *
 * The followings are the available model relations:
 * @property Archivo[] $archivos
 * @property Acuerdo $idAcuerdo
 * @property Usuario $idUsuario
 */
class StatusAcuerdoParticipante extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'statusacuerdoparticipante';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_acuerdo, id_usuario', 'required', 'message' => '{attribute} no puede estar vacío.'),
			array('id_acuerdo, id_usuario', 'numerical', 'integerOnly'=>true),
                        array('id_acuerdo+id_usuario', 'application.extensions.uniqueMultiColumnValidator'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('id, id_acuerdo, id_usuario', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'archivos' => array(self::HAS_MANY, 'Archivo', 'id_statusacuerdoparticipante'),
			'idAcuerdo' => array(self::BELONGS_TO, 'Acuerdo', 'id_acuerdo'),
			'idUsuario' => array(self::BELONGS_TO, 'Usuario', 'id_usuario'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'id_acuerdo' => 'Id Acuerdo',
			'id_usuario' => 'Id Usuario',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search($idMinuta, $idAcuerdo)
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;
               
		$criteria->compare('id',$this->id);
		$criteria->compare('id_acuerdo',$this->id_acuerdo);
		$criteria->compare('id_usuario',$this->id_usuario);
                
                
                $criteria->join = 'INNER JOIN usuario u on id_usuario = u.id ';
                $criteria->join .= 'INNER JOIN acuerdo a on id_acuerdo = a.id ';                
                
                $criteria->condition = 'a.id_minuta = :idMinuta ';
                $criteria->condition .= 'AND id_acuerdo = :idAcuerdo ';                
                
                $criteria->params = array(
                    ':idMinuta' => $idMinuta,
                    ':idAcuerdo' => $idAcuerdo); 

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return StatusAcuerdoParticipante the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
